﻿@inject TeachlyQBank.DbServer.UserServer UserService
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor

@{
    var powerList = UserService.GetNowPower(HttpContextAccessor.HttpContext);
}
@{
    bool isUserInfoDisabled = !powerList.Contains("用户信息管理");
    bool isSystemParamsDisabled = !powerList.Contains("系统参数设置");
    bool isCourseDisabled = !powerList.Contains("课程管理");
    bool isKnowledgeDisabled = !powerList.Contains("知识点与考核内容计划");
    bool isExamPlanDisabled = !powerList.Contains("考试计划管理");
}

<!-- 左侧菜单栏 -->
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.0-rc.5/src/js.cookie.min.js"></script>

<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

    <!-- 最上面的页面标题 -->
    <a class="sidebar-brand d-flex align-items-center justify-content-center">
        <div class="sidebar-brand-icon rotate-n-15">
            <i class="fas fa-laugh-wink"></i>
        </div>
        <div class="sidebar-brand-text mx-3">好老师题库系统 </div>
    </a>

    <!-- 一条分割线 -->
    <hr class="sidebar-divider my-0">

    <!-- 首页 -->
    <li class="nav-item"> 
        <a class="nav-link" asp-controller="UserAndRole" asp-action="Index">
            <i class="fas fa-fw fa-tachometer-alt"></i>
            <span>首页</span>
        </a>
    </li>

    <!-- 一条分割线 -->
    <hr class="sidebar-divider">

    <!-- 第一个大区域的标题 -->
    <div class="sidebar-heading">
        系统设置
    </div>

    <!-- 用户信息管理模块 -->
    <li class="nav-item active" data-menu-id="userInfo">
        <a class="nav-link collapsed @(isUserInfoDisabled ? "disabled" : "")" href="#" data-toggle="collapse" data-target="#collapseTwo"
           aria-expanded="true" aria-controls="collapseTwo">
            <i class="fas fa-fw fa-users"></i>
            <span>用户信息管理</span>
        </a>
        <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                <h6 class="collapse-header">具体的用户信息管理:</h6>
                <a class="collapse-item @(isUserInfoDisabled ? "disabled" : "")" asp-controller="UserAndRole" asp-action="UserInfo">查询所有</a>
            </div>
        </div>
    </li>


    <!-- 系统参数设置模块 -->
    <li class="nav-item active" data-menu-id="systemParams">
        <a class="nav-link collapsed @(isSystemParamsDisabled ? "disabled" : "")" href="#" data-toggle="collapse" data-target="#collapseUtilities"
           aria-expanded="true" aria-controls="collapseUtilities">
            <i class="fas fa-fw fa-cog"></i>
            <span>系统参数设置</span>
        </a>
        <div id="collapseUtilities" class="collapse" aria-labelledby="headingUtilities" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                <h6 class="collapse-header">具体参数设置:</h6>
                <a class="collapse-item @(isSystemParamsDisabled ? "disabled" : "")" asp-controller="UserAndRole" asp-action="ShareUserRole">用户角色管理</a>
                <a class="collapse-item @(isSystemParamsDisabled ? "disabled" : "")" asp-controller="UserAndRole" asp-action="ShareRolePower">角色权限管理</a>
                <a class="collapse-item @(isSystemParamsDisabled ? "disabled" : "")" asp-controller="UserAndRole" asp-action="SharePermission">权限管理</a>
            </div>
        </div>
    </li>


    <!-- 第一个大区域结束了,这是一个分割线 -->
    <hr class="sidebar-divider">

    <!-- 第二个大区域的标题-->
    <div class="sidebar-heading">
        教学内容与考核内容
    </div>

    <!-- 课程管理模块 -->
    <li class="nav-item active" data-menu-id="courseManage">
        <a class="nav-link @(isCourseDisabled ? "disabled" : "")" href="#" data-toggle="collapse" data-target="#collapsePages" aria-expanded="true"
           aria-controls="collapsePages">
            <i class="fas fa-fw fa-chalkboard-teacher"></i>
            <span>课程管理</span>
        </a>
        <div id="collapsePages" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                <h6 class="collapse-header">Login Screens:</h6>
                <a class="collapse-item @(isCourseDisabled ? "disabled" : "")" asp-controller="Course" asp-action="Jump">添加课程</a>
                <a class="collapse-item @(isCourseDisabled ? "disabled" : "")" asp-controller="Course" asp-action="CourseInfo">查看所有课程</a>
                <div class="collapse-divider"></div>
            </div>
        </div>
    </li>

    <!-- 知识点与考核内容计划模块 -->
    <li class="nav-item active" data-menu-id="knowledgePlan">
        <a class="nav-link @(isKnowledgeDisabled ? "disabled" : "")" href="#" data-toggle="collapse" data-target="#SecondItem" aria-expanded="true"
           aria-controls="collapsePages">
            <i class="fas fa-fw fa-lightbulb"></i>
            <span>知识点与考核内容计划</span>
        </a>
        <div id="SecondItem" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                <h6 class="collapse-header">知识点整理:</h6>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Knowledge" asp-action="ShowKnowledge">管理已有知识点</a>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Knowledge" asp-action="AddKnowledge">添加知识点</a>
                <div class="collapse-divider"></div>
                <h6 class="collapse-header">试题答案整理:</h6>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Questions" asp-action="AddQuestionType">添加新题型</a>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Questions" asp-action="ShowQuestionType">管理已有题型</a>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Questions" asp-action="AddJumpQuestion">添加一个新试题</a>
                <a class="collapse-item @(isKnowledgeDisabled ? "disabled" : "")" asp-controller="Questions" asp-action="ShowQuestion">查看试题库</a>
            </div>
        </div>
    </li>


    <!-- 考试计划管理模块 -->
    <li class="nav-item active" data-menu-id="examPlan">
        <a class="nav-link @(isExamPlanDisabled ? "disabled" : "")" href="#" data-toggle="collapse" data-target="#ThirdItem" aria-expanded="true"
           aria-controls="collapsePages">
            <i class="fas fa-fw fa-calendar-check"></i>
            <span>考试计划管理</span>
        </a>
        <div id="ThirdItem" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                <h6 class="collapse-header">Login Screens:</h6>
                <a class="collapse-item @(isExamPlanDisabled ? "disabled" : "")" asp-controller="Paper" asp-action="ManualTestPaper">手工组卷</a>
                <a class="collapse-item @(isExamPlanDisabled ? "disabled" : "")" asp-controller="ExamPlan" asp-action="AddExam">添加考试计划</a>
                <a class="collapse-item @(isExamPlanDisabled ? "disabled" : "")" asp-controller="Paper" asp-action="ShowPaper">展示所有试卷</a>
                <a class="collapse-item @(isExamPlanDisabled ? "disabled" : "")" asp-controller="ExamPlan" asp-action="ExamInfo">查看所有考试计划</a>
            </div>
        </div>
    </li>

    <!-- 第二个大区域结束了,分割线 -->
    <hr class="sidebar-divider d-none d-md-block">

    <!-- 最底部的小按钮 -->
    <div class="text-center d-none d-md-inline">
        <button class="rounded-circle border-0" id="sidebarToggle"></button>
    </div>

</ul>
<!-- 左侧菜单栏 -->
<script>
    document.querySelectorAll(".nav-item").forEach(function (item) {
        var navLink = item.querySelector(".nav-link");
        var collapseElem = item.querySelector(".collapse");

        if (navLink && collapseElem) {
            navLink.addEventListener("click", function () {
                // 存储或移除active状态，取决于它是展开还是关闭
                if (collapseElem.classList.contains('show')) {
                    Cookies.remove(item.dataset.menuId);
                } else {
                    Cookies.set(item.dataset.menuId, 'active');
                }
            });
        }
    });
</script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        document.querySelectorAll(".nav-item").forEach(function (item) {
            if (Cookies.get(item.dataset.menuId) === 'active') {
                // 展开这个项目
                var collapseElem = item.querySelector(".collapse");
                if (collapseElem) {
                    collapseElem.classList.add("show");
                }
            }
        });
    });
</script>
